<template>
  <div class="todo-container">
    <div class="todo-wrap">
      <Header @addtodos="addtodos"/>
      <list :todos="todos" @isChecked="isChecked" @deleteTodos="deleteTodos"/>
      <Footer :todos="todos" @SelectAll="SelectAll" @deleteTodosAll="deleteTodosAll"/>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent,ref } from "vue";

export default defineComponent({
  name: "App",
});
</script>

<script setup lang="ts">
import Header from './components/Header/index.vue'
import List from './components/List/index.vue'
import Footer from './components/Footer/index.vue'
import {nanoid} from 'nanoid'
export interface todosList{
  id:string,
  title:string,
  comment:boolean
}
export type todosType = todosList[]
const todos = ref<todosType>([
  {id:nanoid(),title:'吃饭',comment:false},
  {id:nanoid(),title:'喝酒',comment:true},
  {id:nanoid(),title:'唱歌',comment:false},
  {id:nanoid(),title:'跳舞',comment:false},
])
//添加新的todo
const addtodos = (title:string)=>{
  const newTodo = {id:nanoid(),title,comment:false}
  todos.value.unshift(newTodo);
}
//是否选中任务
const isChecked = (index:number)=>{
  todos.value[index].comment = !todos.value[index].comment
}
//删除单个任务
const deleteTodos = (index:number)=>{
  todos.value.splice(index,1)
}
//全选中
const SelectAll = (commentType:boolean)=>{
  todos.value.forEach(item=>item.comment = commentType)
}
//删除所有完成任务
const deleteTodosAll = ()=>{
  todos.value = todos.value.filter(item=> {
    return !item.comment
  })
}
</script>

<style >
/*base*/
body {
  background: pink;
}

.btn {
  display: inline-block;
  padding: 4px 12px;
  margin-bottom: 0;
  font-size: 14px;
  line-height: 20px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(0, 0, 0, 0.05);
  border-radius: 4px;
}

.btn-danger {
  color: #fff;
  background-color: #da4f49;
  border: 1px solid #bd362f;
}

.btn-danger:hover {
  color: #fff;
  background-color: #bd362f;
}

.btn:focus {
  outline: none;
}

.todo-container {
  width: 600px;
  margin: 0 auto;
}
.todo-container .todo-wrap {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}





</style>
